﻿using AlarmClock.BLL;
using System.Drawing;
using System.Windows.Forms;

namespace AlarmClock.UI
{
    public partial class FrmMessageBox : Form
    {
        private Timer timer1;

        /// <summary>
        /// 构造函数+3
        /// </summary>
        /// <param name="point">父窗体起始点</param>
        /// <param name="width">父窗体宽度</param>
        /// <param name="msg">消息内容</param>
        public FrmMessageBox(Point point, int width, string msg)
        {
            InitializeComponent();
            this.ShowInTaskbar = false;
            this.TopMost = false;
            SetStyle(ControlStyles.UserPaint, true);
            DoubleBuffered = true;

            this.Location = new Point((width - this.Width) / 2 + point.X, point.Y);
            this.ShowMsg.Text = msg;

            this.Load += (s, e) =>
            {
                //提示信息居中显示
                ShowMsg.Location = new Point(
                    (this.Width - ShowMsg.Width) / 2,
                    (this.Height - ShowMsg.Height) / 2
                    );
                timer1.Interval = 888;//显示时间
                timer1.Start();
                PPWin32.AnimateWindow(this.Handle, 200, PPWin32.AW_VER_POSITIVE);
            };

            this.FormClosing += (s, e) =>
            {
                PPWin32.AnimateWindow(this.Handle, 200, PPWin32.AW_SLIDE | PPWin32.AW_HIDE | PPWin32.AW_VER_NEGATIVE);
            };

            timer1 = new Timer();
            timer1.Tick += (s, e) => { this.Close(); };
        }

        /// <summary>
        /// 不占用窗口焦点
        /// </summary>
        protected override bool ShowWithoutActivation => true;
    }
}
